<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>C | 学习笔记</title><meta name="author" content="lzoxun"><meta name="copyright" content="lzoxun"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="概念 语言过程 二进制语言 0101-&gt;汇编语言(助记符)-&gt; B 语言 -&gt; C 语言 -&gt; C++…高级语言   c 语言发展中个开发厂商的 C 语言产生差异，美国国家标准局定制标准语法ANSIC 11 年国际标准组织ISO和国际电工委员会IEC发布最新标准C11 主要编译器GCC、MSVC、Clang、WIN-TC、SUBLIME、Turbo C 等   C 语言优点">
<meta property="og:type" content="article">
<meta property="og:title" content="C">
<meta property="og:url" content="http://example.com/2023/07/22/server/C/C-base/index.html">
<meta property="og:site_name" content="学习笔记">
<meta property="og:description" content="概念 语言过程 二进制语言 0101-&gt;汇编语言(助记符)-&gt; B 语言 -&gt; C 语言 -&gt; C++…高级语言   c 语言发展中个开发厂商的 C 语言产生差异，美国国家标准局定制标准语法ANSIC 11 年国际标准组织ISO和国际电工委员会IEC发布最新标准C11 主要编译器GCC、MSVC、Clang、WIN-TC、SUBLIME、Turbo C 等   C 语言优点">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png">
<meta property="article:published_time" content="2023-07-22T07:14:09.686Z">
<meta property="article:modified_time" content="2023-07-22T07:14:09.686Z">
<meta property="article:author" content="lzoxun">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/2023/07/22/server/C/C-base/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":true,"top_n_per_article":1,"unescape":true,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'C',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-07-22 15:14:09'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const now = new Date()
          const hour = now.getHours()
          const isNight = hour <= 6 || hour >= 18
          if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
          else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (false) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">108</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="学习笔记"><span class="site-name">学习笔记</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">C</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-07-22T07:14:09.686Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-07-22T07:14:09.686Z" title="更新于 2023-07-22 15:14:09">2023-07-22</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="C"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="概念"><a href="#概念" class="headerlink" title="概念"></a>概念</h2><ul>
<li>语言过程<ul>
<li>二进制语言 0101-&gt;汇编语言(助记符)-&gt; B 语言 -&gt; C 语言 -&gt; C++…高级语言</li>
</ul>
</li>
<li>c 语言发展中个开发厂商的 C 语言产生差异，美国国家标准局定制标准语法<code>ANSIC</code><ul>
<li>11 年国际标准组织<code>ISO</code>和国际电工委员会<code>IEC</code>发布最新标准<code>C11</code></li>
<li>主要编译器<code>GCC</code>、<code>MSVC</code>、Clang、WIN-TC、SUBLIME、Turbo C 等</li>
</ul>
</li>
<li>C 语言优点<ul>
<li>基础性语言</li>
<li>语法简洁紧凑方便灵活</li>
<li>运算符数据结构丰富</li>
<li>结构化，模块化编程</li>
<li>移植性好，执行效率高</li>
<li>允许直接操作硬件</li>
</ul>
</li>
</ul>
<h2 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h2><h3 id="基本要求"><a href="#基本要求" class="headerlink" title="基本要求"></a>基本要求</h3><ul>
<li>注意<ul>
<li>头文件正确包含的重要性</li>
<li>以函数为单位进行编程</li>
<li>程序包括<code>声明部分</code>+<code>实现部分</code></li>
<li>main return 的值是给它父进程看的($?状态码)</li>
<li>多用空格与换行</li>
<li>注释 &#x2F;星星&#x2F;<ul>
<li>#if 0 换行 xxx 换行 xx #endif</li>
</ul>
</li>
</ul>
</li>
<li>算法:解决问题的方法(流程图,NS 图，有限状态机 FSM 等显示出来)</li>
<li>程序：用某种语言实现算法</li>
<li>进程:</li>
<li>防止写越界、防止内存泄露、谁打开谁关闭、谁申请谁释放</li>
</ul>
<h3 id="数据类型、运算符、表达式"><a href="#数据类型、运算符、表达式" class="headerlink" title="数据类型、运算符、表达式"></a>数据类型、运算符、表达式</h3><h4 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h4><ul>
<li><p>类型转换</p>
<ul>
<li>a (int)b;</li>
</ul>
</li>
<li><p>数据类型</p>
<ul>
<li><p>基本数据类型</p>
<ul>
<li><p>数值类型</p>
<ul>
<li><p>整型</p>
<ul>
<li>短整型<code>short</code></li>
<li>整型<code>int</code></li>
<li>长整型<code>long</code></li>
<li>三种还区分有符号(默认)和无符号，同样占 32 位的有符号整型，最高位代表 0 正 1 负<ul>
<li>范围不同，表示的大小是一样的，-128 和+127 间个数 等于 0 到 255 的个数</li>
</ul>
</li>
</ul>
</li>
<li><p>浮点型</p>
<ul>
<li>单精度<code>flat</code></li>
<li>双精度<code>double</code></li>
<li>科学技术法:3e-23 ，3 乘以 10 的负 23 次方</li>
</ul>
</li>
</ul>
</li>
<li><p>字符类型<code>char</code></p>
</li>
<li><p>布尔<code>bool</code>（需要引入头文件 stdbool.h）</p>
</li>
</ul>
</li>
<li><p>构造类型</p>
<ul>
<li>数组</li>
<li>结构体</li>
<li>公用体</li>
<li>枚举类型</li>
</ul>
</li>
<li><p>指针类型</p>
</li>
<li><p>空类型<code>void</code></p>
</li>
</ul>
</li>
<li><p>重点</p>
<ul>
<li><p>所占字节</p>
<ul>
<li>数据类型所占字节随着机器的不同而不同。</li>
</ul>
</li>
<li><p>储存区别</p>
</li>
<li><p>不同数据类型的转化</p>
<ul>
<li>显式(手动，强制类型转化)</li>
<li>隐式</li>
</ul>
</li>
<li><p>特殊性</p>
<ul>
<li><p>bool 需要引入头文件</p>
</li>
<li><p>float 类型的比较，不能和一个确切的值相比,是一个大概范围的表示，</p>
</li>
<li><p>chat 类型是否有符号，不确定</p>
</li>
<li><p>不同形式的 0 值<code>0 &#39;0&#39; &quot;0&quot; &#39;\0&#39;</code></p>
</li>
<li><p>数据类型与后续代码的输入输出相匹配</p>
</li>
<li><p>字符转义字符</p>
<ul>
<li>‘\567’ :斜杠后三位当做八进制来看</li>
<li>‘\x9f’ :\x 开头当做十六进制看</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h4 id="变量与常量"><a href="#变量与常量" class="headerlink" title="变量与常量"></a>变量与常量</h4><ul>
<li><p>变量(值随时变化的量)</p>
<ul>
<li><p>格式:[存储类型] 数据类型 标识符 &#x3D; 值;</p>
<ul>
<li><p>标识符：数字字母下划线组成的序列，数字不能开头</p>
</li>
<li><p>数据类型:基础+构造+…所有数据类型</p>
</li>
<li><p>值:类型与值匹配</p>
</li>
<li><p>储存类型</p>
<ul>
<li><p>auto:默认(储存栈中)</p>
<ul>
<li>空间自动分配，自动释放，自动回收，不需要我们操作空间</li>
</ul>
</li>
<li><p>static:静态类型</p>
<ul>
<li>没有赋值一定会自动初始化为 0 或 null</li>
<li>变量的值有继承性质,如：函数中的 static 变量，函数调用多次，这个变量是共用的,只分配一块空间</li>
<li>修饰全局变量后，不会音响到其他文件中同名的全局变量</li>
<li>修饰函数后,该函数不能在其他.c 文件中使用</li>
</ul>
</li>
<li><p>register:寄存器类型(建议编译器将变量存储位置在寄存器上)</p>
<ul>
<li>寄存器存在 CPU 中，将变量直接声明在 CPU 中速度快，但资源少</li>
<li>是否能成功由 gcc 判断，条件如下<ul>
<li>只能是局部变量</li>
<li>大小限制，32 位的环境下只能，寄存变量只能是&lt;&#x3D;32 位的</li>
<li>寄存器中没有地址，寄存器类型变量无法打印或查看地址</li>
</ul>
</li>
</ul>
</li>
<li><p>extern:说明型</p>
<ul>
<li>不是定义变量，不能更改被说明的变量和类型</li>
<li>extern int i;在该文件中是使用到的 i 不是自动定义的，去用其他文件定义的</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>声明周期</p>
</li>
<li><p>作用范围</p>
<ul>
<li>全局和局部<ul>
<li>内部作用域优先级大于外面作用域</li>
</ul>
</li>
<li>全局变量<ul>
<li>作用范围:从定义开始到程序执行结束</li>
</ul>
</li>
<li>局部变量<ul>
<li>作用范围:从定义开始到当前大括号块结束</li>
<li>函数中的变量</li>
<li>修饰符不同代表的局部变量用法也不一样</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>常量(程序执行过程中值不会发生变化的量)</p>
<ul>
<li>整型常量 1，33，44</li>
<li>实型常量 2.33,4.555</li>
<li>字符常量 由单引号引起来的单个字符或转义字符’a’,’\t’</li>
<li>字符串常量 由双引号引起的一个过多个字符序列</li>
<li>标识常量 #define PI 3.14(#define 宏名 宏体);编写使用宏名，预处理后<code>完全替换</code>宏体,不校验<ul>
<li>带参数：#define MAX(a,b) a&gt;b?a:b</li>
<li>带参数：#define MAX(a++,b++) a&gt;b?a:b;替换后:a++&gt;b++?a++:b++</li>
<li>处理问题：#define MAX(a++,b++) ({int A&#x3D;a,B&#x3D;b; A&gt;B?A:B;});替换后:a++&gt;b++?a++:b++</li>
<li>宏的运行:在程序预处理接口执行，不占用运行时间，占用编译时间，一改全改</li>
<li>对比函数:作用类似，安全性低，效率更高（对比宏，函数接收到变量直接进行运算）</li>
</ul>
</li>
</ul>
</li>
</ul>
<h4 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h4><ul>
<li><p>运算符</p>
<ul>
<li>算术运算符(+, -, *, &#x2F;, %, ++, –)<ul>
<li><code>+|-</code> 单目的画是正负</li>
<li><code>%</code>:取余两边必须是整数</li>
<li><code>/</code>:被除数(分母或右边的)不能是 0</li>
<li>自增自减:元算法在前，先进行计算再取变量使用，否则先用，之后再计算</li>
</ul>
</li>
<li>关系运算符(&lt; &lt;&#x3D; &#x3D;&#x3D; &gt;&#x3D; &gt; !&#x3D;)</li>
<li>逻辑运算符(! &amp;&amp; ||)<ul>
<li>短路特性:&amp;&amp; 左边为假，不会走右边表达式; || 左边为真，不会走右边表达式</li>
</ul>
</li>
<li>位运算符(&lt;&lt; &gt;&gt; ~ | ^ &amp;)<ul>
<li>&lt;&lt; 左移(相当于乘 2)<ul>
<li>二进制向左移动一位，右边补上一个 0</li>
<li>B1100 -&gt; B0001 1000</li>
</ul>
</li>
<li>&gt;&gt; 右移(相当于除 2)<ul>
<li>二进制向右移动一位，右边去掉一个 0</li>
<li>B1100 -&gt; B0110</li>
</ul>
</li>
<li>~ 取反<ul>
<li>不考虑符号位，二进制 1 变 0，0 变 1</li>
<li>B1100 -&gt; B0011</li>
</ul>
</li>
<li>| 按位或<ul>
<li>两个二进制操作数，同位置一边为 1 就为 1，两边为 0 才为 0</li>
<li>B1100 | B1010 &#x3D;&gt; B1110</li>
</ul>
</li>
<li>&amp; 安位与<ul>
<li>两个二进制操作数, 同位置一边为 0 就为 0，两边为 1 才为 1</li>
<li>B1100 | B1010 &#x3D;&gt; B1000</li>
</ul>
</li>
<li>^ 按为异或<ul>
<li>连个二进制操作数，相同为 0，不同为 1</li>
<li>B1100 ^ B1010 &#x3D;&gt; B0110</li>
</ul>
</li>
<li>理解</li>
</ul>
</li>
<li>赋值运算符（&#x3D;）<ul>
<li>+&#x3D;，-&#x3D;，*&#x3D;，&#x2F;&#x3D;</li>
</ul>
</li>
<li>条件运算符(三目运算 ？：)</li>
<li>逗号运算符（都会 主要运用连续定义变量）</li>
<li>指针运算符(星号 A,获取地址 &amp;B, int 星 A &#x3D; &amp;B)<br><code>int *p = &amp;j</code></li>
<li>求字节数(sizeof(int),sizeof(xxx))</li>
<li>强制转换类型 a &#x3D; (int)b<ul>
<li>转换只是一个过程，并不会改变 b 的值</li>
</ul>
</li>
<li>分量运算符</li>
<li>下标运算符</li>
<li>其他</li>
</ul>
</li>
<li><p>结合性</p>
</li>
<li><p>优先级</p>
</li>
<li><p>运算符的特殊用法</p>
</li>
<li><p>为运算的重要意义</p>
</li>
</ul>
<h4 id="表达式"><a href="#表达式" class="headerlink" title="表达式"></a>表达式</h4><h3 id="输入输出专题"><a href="#输入输出专题" class="headerlink" title="输入输出专题"></a>输入输出专题</h3><ul>
<li><p>格式化输入输出函数 scanf、printf</p>
<ul>
<li>printf<ul>
<li>int printf(const char *format,…)<ul>
<li>format:”%[可选修饰符]格式字符，替换逗号后面的变量”<ul>
<li>变量什么类型，建议用响应的格式字符输出，需要匹配</li>
<li>格式字符<ul>
<li>d,i:十进制整型数</li>
<li>x,o:将值通过十六，八进制无符号整数输出</li>
<li>u:无符号十进制整型</li>
<li>c:单一字符</li>
<li>s:字符串</li>
<li>f:浮点小数</li>
<li>e:将输出的值通过指数形式科学计数法输出</li>
</ul>
</li>
<li>修饰符<ul>
<li>m|.n<ul>
<li>整数 j:设置输出宽带，比实际小忽略，否则前面补空格，printf(“i &#x3D; %4d”,i)</li>
<li>浮点数:%8,1f,指定输出需要 8 位，小数点保留一位四舍五入</li>
<li>字符串:%.5s，只输出 5 个字符</li>
</ul>
</li>
<li>%-10d 补空格后左对齐</li>
<li>%010d 补 0 后左对齐,%后面跟 0</li>
<li>%#x:十六进制和八进制输出添加 0x 或 0 等前缀</li>
<li>%lxxx:d o x u 格式字符，指定输出精度为 long，e f g 输出精度指定为 double</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>scanf 接收用户输入<ul>
<li>int scanf(const char *format,&amp;变量地址)<ul>
<li>修饰符与 printf 类似，不能有提示信息，并且后面的是变量地址</li>
<li>scanf(“%d,%f”,&amp;i,&amp;f) :动态输入</li>
<li>scanf %s 不建议使用，不能缺点储存空间大小</li>
<li>scanf 放在循环结构中要注意能否接收到有效值</li>
<li>输入是出现分割符号,后面的都无法输出了 W</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>字符输入输出函数 getchar、putchar</p>
<ul>
<li>getchar 接收用户输入</li>
<li>putchar 显示打印出字符</li>
</ul>
</li>
<li><p>字符串输入输出函数 gets(!) 、puts</p>
<ul>
<li>gets 接收用户输入字符串，不建议用，可以用 fgets 代替<ul>
<li>gets 储存数据内存空间有指定的固定大小的，但是用户输入无限制，空间越界用户</li>
</ul>
</li>
<li>puts 输出</li>
</ul>
</li>
</ul>
<h3 id="进制"><a href="#进制" class="headerlink" title="进制"></a>进制</h3><ul>
<li>十转二<ul>
<li>除二(16,除 8)取余数，倒数</li>
</ul>
</li>
<li>Bxx、0xxx、0xFFF,B O Ox 前缀分别代表二进制八进制和十六进制</li>
<li>整型数据已补码相似储存<ul>
<li>正数补码就是他二进制本身</li>
<li>负数补码是它绝对值的二进制– 取反 – +1</li>
</ul>
</li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/MISSXIAOJJ/article/details/107425401">源码反码</a></li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">23</span><br><span class="line">十进制转二进制</span><br><span class="line">不断除以2，从下往上取余</span><br><span class="line"></span><br><span class="line">二进制</span><br><span class="line">0001 0111  (有八位)</span><br><span class="line"></span><br><span class="line">一个二进制为一位(Byte)</span><br><span class="line">八位 为 一个字节(b)</span><br><span class="line">1KB = 1024个字节(b)</span><br><span class="line">1MB = 1024KB</span><br><span class="line">....</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">二转八进制</span><br><span class="line">三个二进制表示一个八进制</span><br><span class="line">010 111</span><br><span class="line">2     7</span><br><span class="line">对应   4 2 1 等于7</span><br><span class="line">4 2 1 通过2的次方得到的</span><br><span class="line"></span><br><span class="line">二转十六进制</span><br><span class="line">四个二进制表示7一个十六进制</span><br><span class="line">0001 0111</span><br><span class="line">1       7</span><br><span class="line"></span><br><span class="line">二进制转十进制</span><br><span class="line">0b10111</span><br><span class="line">32 16 8 4 2 1</span><br><span class="line">1*1 + 1*2 +1*4 + 0*8 + 1*16  = 23</span><br></pre></td></tr></table></figure>

<h3 id="流程控制"><a href="#流程控制" class="headerlink" title="流程控制"></a>流程控制</h3><h4 id="顺序"><a href="#顺序" class="headerlink" title="顺序"></a>顺序</h4><ul>
<li>语句逐行执行</li>
</ul>
<h4 id="选择"><a href="#选择" class="headerlink" title="选择"></a>选择</h4><ul>
<li>if-else</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(a = <span class="number">1</span>)&#123;</span><br><span class="line">    cmd1;</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    cmd2</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta"># <span class="keyword">else</span> 与最近的<span class="keyword">if</span>匹配，嵌套的<span class="keyword">if</span>-<span class="keyword">else</span>中也一样，所以多行的话尽量写上大括号，除非只有一行</span></span><br></pre></td></tr></table></figure>

<ul>
<li>switch-case</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">switch</span>(<span class="built_in">exp</span>)&#123;</span><br><span class="line">    <span class="keyword">case</span> 常量或常量表达式: <span class="built_in">printf</span>(<span class="string">&#x27;语句主体&#x27;</span>); <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">1</span>: <span class="built_in">printf</span>(<span class="string">&#x27;a=1&#x27;</span>); <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">2</span>: <span class="built_in">printf</span>(<span class="string">&#x27;a=2&#x27;</span>); <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">3</span>:</span><br><span class="line">    <span class="keyword">case</span> <span class="number">4</span>: <span class="built_in">printf</span>(<span class="string">&#x27;a=3或a=4&#x27;</span>); <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">default</span>: <span class="built_in">printf</span>(<span class="string">&#x27;其他我预料不到的情况&#x27;</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="循环"><a href="#循环" class="headerlink" title="循环"></a>循环</h4><ul>
<li>while</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">while</span>(<span class="type">bool</span>)&#123;</span><br><span class="line">    loop</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"># 条件成立 则 执行循环体，否则跳出不执行</span><br><span class="line"># 最少执行次数为<span class="number">0</span></span><br></pre></td></tr></table></figure>

<ul>
<li>do-while</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">do</span>&#123;</span><br><span class="line">    loop</span><br><span class="line">&#125;<span class="keyword">while</span>(<span class="built_in">exp</span>)</span><br><span class="line"></span><br><span class="line"># 执行循环体 再判断条件，成立继续循环体，否则跳出不执行</span><br><span class="line"># 最少执行次数为<span class="number">1</span></span><br></pre></td></tr></table></figure>

<ul>
<li>for</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(exp1,exp2,exp3)&#123;</span><br><span class="line">    loop</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"># 执行表达式<span class="number">1</span>，判断表达式<span class="number">2</span>是否成立，如果不成立直接退出，成立执行loop，再走表达式<span class="number">3</span>，继续验证表达式<span class="number">2</span>，成立走loop,否则退出循环</span><br><span class="line"># 最少执行次数为<span class="number">0</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(,exp2,)&#123;</span><br><span class="line">    loop；</span><br><span class="line">    i++...</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta"># for 只是把for之前的初始化 和for之后的条件判断、循环体、变化语句，结构化了,结构在，就可以正常运行</span></span><br><span class="line"># 是可以的，只是exp1,<span class="number">3</span>什么都没做</span><br><span class="line"># 将自增操作放到循环体中，自增完，执行表达式<span class="number">3</span>,空不报错，会继续验证表达式<span class="number">2</span></span><br></pre></td></tr></table></figure>

<ul>
<li><p>if-goto</p>
<blockquote>
<p>无条件跳转，且不能跨函数，破坏程序结构，不建议使用</p>
</blockquote>
</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">xxxxx</span><br><span class="line">tag:</span><br><span class="line">xxxxx</span><br><span class="line">xxxxx</span><br><span class="line">xxxxx</span><br><span class="line"><span class="keyword">goto</span> tag:</span><br><span class="line">xxxxx</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="辅助控制关键字"><a href="#辅助控制关键字" class="headerlink" title="辅助控制关键字"></a>辅助控制关键字</h4><ul>
<li>break:跳出所在整个循环(for,while…),一层</li>
<li>continue:跳出本次循环，不执行 continue 后面的内容,进入自增后的下次循环</li>
</ul>
<h3 id="数组"><a href="#数组" class="headerlink" title="数组"></a>数组</h3><h4 id="二维数组"><a href="#二维数组" class="headerlink" title="二维数组"></a>二维数组</h4><blockquote>
<p>数组:可以产生一个<code>相同类型</code>并且<code>连续</code>的内存空间地址</p>
</blockquote>
<ul>
<li>定义[可省略的存储类型] 数据类型 标识符[长度]<ul>
<li>int arr[3] &#x3D; {1,2,3}</li>
</ul>
</li>
<li>初始化<ul>
<li>不初始化:int arr[3];</li>
<li>半初始化:int arr[3] &#x3D; {1}</li>
<li>全初始化:int arr[3] &#x3D; {1,2,3}</li>
</ul>
</li>
<li>元素引用<ul>
<li>标识符[下标]</li>
<li>下标:0 - (len - 1)</li>
</ul>
</li>
<li>数组名[表示地址的一个常量]<code>本身就是一个地址 scanf等需要地址符号的地方不需要&amp;</code><ul>
<li>数组名：起始位置，声明后不能直接被赋值</li>
<li>起始位置就是第一个元素的位置</li>
</ul>
</li>
<li>数组越界<ul>
<li>一个三元素整型数组，假设当前环境，一个整型占四个自己，那么数组占用 1-12 的空间地址，如果再操作 arr[3] 第四个元素，使用 13-16 所在空间，这就产生数组越界</li>
<li>数组越界程序无法判断为语法错误，需要自己注意</li>
</ul>
</li>
</ul>
<h4 id="二维数组-1"><a href="#二维数组-1" class="headerlink" title="二维数组"></a>二维数组</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">-   定义,初始化[可省略储存类型] 数据类型 标识符[行下标][列下标]</span><br><span class="line">    -   arr[M][n] ，M 行，N 列，下标位置 arr[<span class="number">0</span>][<span class="number">0</span>] 到 arr[M-<span class="number">1</span>][n-<span class="number">1</span>]</span><br><span class="line">    -   初始化：arr[M][n] = &#123;&#123;<span class="number">00</span>,<span class="number">01</span>,<span class="number">02</span>&#125;,&#123;<span class="number">10</span>,<span class="number">11</span>,<span class="number">12</span>&#125;&#125;</span><br><span class="line">    -   初始化：arr[M][n] = &#123;&#123;<span class="number">00</span>&#125;,&#123;<span class="number">10</span>,<span class="number">11</span>&#125;&#125; ;未初始化默认为 <span class="number">0</span></span><br><span class="line">    -   初始化：arr[M][n] = &#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>&#125; ;按内存顺序复制，不能跳过</span><br><span class="line">    -   M 行号可以省略，根据列和值的个数自动计算行号</span><br><span class="line">    -   地址与一维数组一样</span><br><span class="line">-   元素引用</span><br><span class="line">    -   arr[<span class="number">1</span>][<span class="number">1</span>]</span><br><span class="line">-   储存形式</span><br><span class="line">    -   顺序储存，按行储存</span><br><span class="line">-   深入理解二维数组</span><br><span class="line">    -   arr[<span class="number">2</span>][<span class="number">3</span>] ==&gt; 看成:[[<span class="number">00</span>,<span class="number">01</span>,<span class="number">02</span>],[<span class="number">10</span>,<span class="number">11</span>,<span class="number">12</span>]]</span><br><span class="line">    -   多维数组以此类推:arr[<span class="number">2</span>][<span class="number">3</span>][<span class="number">4</span>] arr[<span class="number">00</span>],是一个四元素数组</span><br><span class="line">    -   arr+<span class="number">1</span>,不是跳转一个元素自己大小，而是一行元素字节大小</span><br><span class="line">-   练习题</span><br><span class="line">    -   行列互换</span><br><span class="line">    -   求二维数组的最大值，以及所在位置</span><br><span class="line">    -   求各行与各列的和</span><br></pre></td></tr></table></figure>
<h4 id="字符数组"><a href="#字符数组" class="headerlink" title="字符数组"></a>字符数组</h4><ul>
<li>定义，初始化<ul>
<li>[可省略的存储类型] 数据类型 标识符[长度]</li>
<li>单字符初始化:char arr[3] &#x3D; {‘a’,’b,’c’}</li>
<li>字符串常量初始化:</li>
</ul>
</li>
<li>存储特点<ul>
<li>主要与普通数组差别最后会有一个尾 0<code>\0</code>作为结束标记</li>
</ul>
</li>
</ul>
<h4 id="字符串常用函数"><a href="#字符串常用函数" class="headerlink" title="字符串常用函数"></a>字符串常用函数</h4><blockquote>
<p>引入头文件 string.h</p>
</blockquote>
<p>char str[32] &#x3D; ‘hello’<br>char str2[32] &#x3D; ‘hello\0word’</p>
<ul>
<li>puts(arr):输出</li>
<li><code>strlen</code> 与 <code>sizeof</code><ul>
<li><code>strlen</code>：计算以<code>\0</code>结束的字符串长度(不包括尾 0)<ul>
<li>strlen(str):结果为 5</li>
<li>strlen(str2):结果为 5 ,以尾 0 作为结束标识符</li>
</ul>
</li>
<li><code>sizeof</code>:查看 str 占用的内存大小<ul>
<li>sizeof(str):结果为 6 ，去了六个字节</li>
<li>sizeof(str2):结果为 11</li>
</ul>
</li>
</ul>
</li>
<li>字符串数组重新赋值<ul>
<li>str &#x3D; ‘abcde’; 是错误的</li>
<li>strcopy(str,’abcde’)；需要保证 copy 的串不能超过 str 定义的字节大小,否则<code>产生越界</code></li>
<li>strncopy(str,’abcde’,32[size,防止越界])；无论 copy 的串多大，我只要参数三的大小</li>
</ul>
</li>
<li>连接<ul>
<li>strcat(str,” “):str 后连接上一个空格，覆盖 str 的尾 0，并添加一个新的尾 0，<code>注意大小，防止越界</code></li>
<li>strncat(str,” “,SIZE):从参数二取最大 SIZE 个字节，追加到参数一的后面，没有 SIZE 个字节就取到尾 0 为止</li>
</ul>
</li>
<li>比较<ul>
<li>strcmp(str,str2)<ul>
<li>通过 ASCII 比较，逐个字符比较<ul>
<li>相同:0</li>
<li>参数一大:正值</li>
<li>参数一小:负值</li>
</ul>
</li>
</ul>
</li>
<li>strncmp(str,str2,5):只比较前五个</li>
</ul>
</li>
<li>练习<ul>
<li>计算一个串中单词个数</li>
</ul>
</li>
</ul>
<h3 id="指针"><a href="#指针" class="headerlink" title="指针"></a>指针</h3><blockquote>
<p>指针就是具有指向作用的地址，单独空间 A 地址不能认为是指针，而是要空间 B 储存的空间 A 地址才叫指针，这个 B 中储存的地址可以让 B 通过它获取另外一个地方的值</p>
</blockquote>
<h4 id="变量与地址"><a href="#变量与地址" class="headerlink" title="变量与地址"></a>变量与地址</h4><ul>
<li>变量<ul>
<li>对内存一块一块空间抽象命名(给我们看的,称呼，别名)</li>
</ul>
</li>
<li>地址<ul>
<li>地址是内存中一块空间的编号,地址等价于指针，指向一块空间</li>
<li>如:林锦天城.10 号是永辉超市<ul>
<li>xxx.10 号就是地址</li>
<li>永辉超市这个名称就是变量</li>
<li>倒闭了我接手,改名永辉大超市后，变量名发生了改变，但是地址是不变的</li>
</ul>
</li>
</ul>
</li>
<li>表达式的*：取值的作用</li>
</ul>
<p>指针案例 1</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> i = <span class="number">1</span>; <span class="comment">// 给值为1的一个内存空间命名为i(生成地址 0x1000)</span></span><br><span class="line"><span class="type">int</span> *p; <span class="comment">// 通过`int *`，定义一个命名为p准备作为的`一级指针变量`的空间(0x1001)</span></span><br><span class="line">        <span class="comment">// p是第一个保存`0x1000`这个地址的变量，也可以叫一级指针变量，`0x1000`这个具有指向作用的地址就是指针</span></span><br><span class="line">        <span class="comment">// 把指针指向a,a = &amp;i，把指针指向p，就是p=&amp;i;(如果有定义 int *a 的话)</span></span><br><span class="line">p = &amp;i; <span class="comment">// 将i表示的那个空间地址`0x1000`赋值给p，也就是让p指向i，0x1001存着0x1000地址号</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">i = <span class="number">1</span></span><br><span class="line">&amp;i = <span class="number">0x1000</span></span><br><span class="line">p = <span class="number">0x1000</span>  <span class="comment">//</span></span><br><span class="line">&amp;p = <span class="number">0x1001</span> <span class="comment">//p这块储存0x1000</span></span><br><span class="line">*p = <span class="number">1</span> <span class="comment">//*p -&gt;*(0x1000) :去p指向的地址0x1000中取值(不是p自己的地址)</span></span><br></pre></td></tr></table></figure>

<p>指针案例 2</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> i = <span class="number">1</span>; <span class="comment">// 给值为1的一个内存空间命名为i(生成地址 0x1000)</span></span><br><span class="line"><span class="type">int</span> *p; <span class="comment">// 通过`int *`，定义一个命名为p准备作为的`一级指针变量`的空间(0x1001)</span></span><br><span class="line">        <span class="comment">// p是第一个保存`0x1000`这个地址的变量，也可以叫一级指针变量，`0x1000`这个具有指向作用的地址就是指针</span></span><br><span class="line">        <span class="comment">// 把指针指向a,a = &amp;i，把指针指向p，就是p=&amp;i;(如果有定义 int *a 的话)</span></span><br><span class="line">p = &amp;i; <span class="comment">// 将i表示的那个空间地址`0x1000`赋值给p，也就是让p指向i，0x1001存着0x1000地址号</span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> **q; <span class="comment">//通过`int **` 定义一个命名为q，准备作为`二级指针变量`的空间(0x1002)</span></span><br><span class="line">q = &amp;p; <span class="comment">//将P的地址`0x1001`赋值给了q</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">i = <span class="number">1</span></span><br><span class="line">&amp;i = <span class="number">0x1000</span></span><br><span class="line">p = <span class="number">0x1000</span>  <span class="comment">//</span></span><br><span class="line">&amp;p = <span class="number">0x1001</span> <span class="comment">//p这块储存0x1000</span></span><br><span class="line">*p = <span class="number">1</span> <span class="comment">//*p -&gt;*(0x1000) :去p指向的地址0x1000中取值(不是p自己的地址)</span></span><br><span class="line"></span><br><span class="line">q = <span class="number">0x1001</span></span><br><span class="line">&amp;q = <span class="number">0x1002</span></span><br><span class="line">*q = *(<span class="number">0x1001</span>) = <span class="number">0x1000</span> <span class="comment">//获取0x1001的值 也就是 0x1000</span></span><br><span class="line">**q = *(*(<span class="number">0x1001</span>)) = *(<span class="number">0x1000</span>) = <span class="number">1</span>;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="指针与指针变量"><a href="#指针与指针变量" class="headerlink" title="指针与指针变量"></a>指针与指针变量</h4><ul>
<li>指针具有指向作用的地址(或被指针变量储存起来，能通过它获取相应值的地址)</li>
<li>指针变量:储存指针地址的变量</li>
</ul>
<h4 id="直接访问与间接访问"><a href="#直接访问与间接访问" class="headerlink" title="直接访问与间接访问"></a>直接访问与间接访问</h4><ul>
<li>直接范围<ul>
<li>上例通过&amp;i 访问</li>
</ul>
</li>
<li>间接访问<ul>
<li>p | *q</li>
</ul>
</li>
</ul>
<h4 id="空指针与野指针"><a href="#空指针与野指针" class="headerlink" title="空指针与野指针"></a>空指针与野指针</h4><ul>
<li>空指针<ul>
<li>定义好，暂不知道什么使用用的情况</li>
<li>int *p&#x3D;NULL; NULL 宏一般值为 0<ul>
<li>系统上 0 号空间不分配给任何进程</li>
<li>操作*p 就是乱操作 0 号空间，系统会报错</li>
</ul>
</li>
</ul>
</li>
<li>野指针<ul>
<li>某个指向不确定的指针，定义好没有指向空间，也没指向 NULL 的情况产生</li>
<li>int *p; 直接使用*p, auto 的 int *会产生一个随机值,直接将这个随机值当做地址使用，的情况之一</li>
<li>空指针是为了防止野指针的产生</li>
</ul>
</li>
</ul>
<h4 id="空类型"><a href="#空类型" class="headerlink" title="空类型"></a>空类型</h4><ul>
<li>void int *p;可以与其他类型指针数据交换赋值<ul>
<li>不确定指令类型的时候使用</li>
<li>百搭的指针类型</li>
</ul>
</li>
</ul>
<h4 id="定义与初始化的书写规则"><a href="#定义与初始化的书写规则" class="headerlink" title="定义与初始化的书写规则"></a>定义与初始化的书写规则</h4><ul>
<li>int *p; int* p;都行</li>
</ul>
<h4 id="指针运算"><a href="#指针运算" class="headerlink" title="指针运算"></a>指针运算</h4><ul>
<li>&amp;：取地址</li>
<li>*：取指向目标的值</li>
<li>关系运算:</li>
<li>++&#x2F;–</li>
</ul>
<h4 id="指针与数组"><a href="#指针与数组" class="headerlink" title="指针与数组"></a>指针与数组</h4><ul>
<li>指针与一维数组</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> arr[<span class="number">3</span>] = &#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>&#125;</span><br><span class="line"><span class="comment">// arr 等同于arr+0 的地址 也等同于 arr[0] 的地址</span></span><br><span class="line"><span class="comment">// arr+1 的地址等同于 arr[1]，加不是移动一个字节。而是移动数组类型元素所在字节的个数</span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> *p = arr;</span><br><span class="line"></span><br><span class="line"><span class="comment">// arr[i] == *(arr+i)[因为arr是地址，偏移i的地址] == *(p+i)[p指针变量，储存着指针地址] == p[i] == 1,2,3</span></span><br><span class="line"><span class="comment">// &amp;arr[i] == arr+i == p+i == p[i] == 0xxxx</span></span><br><span class="line"><span class="comment">// arr 与 p 的区别:arr是数组名，一个表示地址的常量；p是一个变量，存放地址的变量</span></span><br><span class="line"><span class="comment">// 在p没有++/--偏移的使用 p和arr是一样的</span></span><br><span class="line"><span class="comment">// 搞清除p+1与p++的差别，前者p并没有变，只是去取下一个元素的值了，p++,是使p不指向arr，而是指向arr[1]</span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ul>
<li>指针与二维数组</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 二维数组arr[2][3],认为是两行三类，一维数组+1移动一个数组元素，行指针，二维数组arr+1，直接从arr[0][0],跳到arr[1][0],称为列指针</span></span><br><span class="line"><span class="comment">// arr[i][j]的值是，arr先移动i行，取值，在移动j列，取值: *(*(arr+i)+j)，地址相当于 *(arr+i)+j</span></span><br><span class="line"><span class="comment">// 如果直接int *p = arr;警告,p+i移动i个元素，arr+i是移动i行</span></span><br></pre></td></tr></table></figure>

<ul>
<li>指针与字符数组</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">char</span> str[] = <span class="string">&quot;string&quot;</span>;</span><br><span class="line"><span class="type">char</span> *p = str+<span class="number">3</span>;</span><br><span class="line"></span><br><span class="line"><span class="built_in">puts</span>(str)</span><br><span class="line"><span class="built_in">puts</span>(p) <span class="comment">//ing ，把p指向的地址开始依次输出到尾0结束</span></span><br></pre></td></tr></table></figure>

<h4 id="const-与指针"><a href="#const-与指针" class="headerlink" title="const 与指针"></a>const 与指针</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> * const int a //变量a常量化，在后面值不能更改，对比宏可以检测语法</span></span><br><span class="line"><span class="comment"> * int const a</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * const int *p //常量指针，和下面int提前的没差别，如果普通指针指向const变量是会被修改的，所以需要用常量指针</span></span><br><span class="line"><span class="comment"> * int const *p //常量指针，指针指向的目标变量值不能改变，指向可以改变</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * int *const p //指针常量，指针指向的目标变量值可以能变，指向不能改变，只能指向最开始指向的变量</span></span><br><span class="line"><span class="comment"> * const int *const p //指针常量又是常量指针,指针指向的目标变量值不能改变，指向也不能改变</span></span><br><span class="line"><span class="comment"> **/</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="指针数组与数组指针"><a href="#指针数组与数组指针" class="headerlink" title="指针数组与数组指针"></a>指针数组与数组指针</h4><ul>
<li>指针数组<ul>
<li>定义: [存储类型] 数据类型 * 数组名[长度]<ul>
<li>int _ arr[2] &#x2F;&#x2F;每个 arr[i]都是一个指针，int * &#x3D; 1，</li>
<li>char _argv[]：argv 是一个数组，数组中有若干个元素，每个元素都是 char _,值就是外部传参内容</li>
</ul>
</li>
</ul>
</li>
<li>数组指针<ul>
<li>定义：[存储类型] 数据类型 (*指针名)[下标]&#x3D;值<ul>
<li>int (*p)[3] -&gt; int[3] *p</li>
<li>正常情况下 int 的 p+1 需要移动 int 所占用的字节数</li>
<li>int[3] 就是移动三个 int 所占用的字节大小。如果二维数组 arr[2][3]的 arr+1 就可以等于 p+1，其他概念个一维数组差不多了</li>
<li>数组指针可以理解为，定义一个指针，这个指针是在某种大小的数组间移动，或设置指针移动做小单位是多少</li>
</ul>
</li>
</ul>
</li>
</ul>
<h4 id="多级指针"><a href="#多级指针" class="headerlink" title="多级指针"></a>多级指针</h4><h3 id="函数"><a href="#函数" class="headerlink" title="函数"></a>函数</h3><h4 id="函数的定义"><a href="#函数的定义" class="headerlink" title="函数的定义"></a>函数的定义</h4><ul>
<li><p>数据类型 函数名(数据类型 形参名,数据类型 形参名 2){}</p>
<ul>
<li>返回值<ul>
<li>数据类型一般为函数 return xx，或 exit(xx)的类型</li>
<li><code>retrun</code>:结束当前函数，main 中结束就是程序结束</li>
<li>main 函数的 return 的值可以在命令中 <code>echo $?</code> 查看，如果没有返回值，就返回里面最后一个函数的返回值</li>
<li>一个进程的返回值是给它父进程看的，main 的父进程就是执行程序的 shell</li>
</ul>
</li>
</ul>
</li>
<li><p>函数名和数组名一样，可以代表函数地址</p>
</li>
</ul>
<h4 id="函数的传参"><a href="#函数的传参" class="headerlink" title="函数的传参"></a>函数的传参</h4><ul>
<li>值传递</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">print_value</span><span class="params">(<span class="type">int</span> a,<span class="type">int</span> b)</span>&#123;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;a=%d,b=%d&quot;</span>,a,b)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">int</span> i = <span class="number">3</span>,j = <span class="number">5</span>;</span><br><span class="line">    print_value(i,j)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>地址传递</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">print_value</span><span class="params">(<span class="type">int</span> *a,<span class="type">int</span> *b)</span>&#123;</span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">     * 定义一个指针变量a，和指针变量b，分别存放&amp;i和&amp;j这两个具有指向作用的地址(指针)</span></span><br><span class="line"><span class="comment">     * *a:获取a指针变量储存指针指向的值</span></span><br><span class="line"><span class="comment">     * *a = *b:指针变量b存储指针指向的值，赋值给a储存指针指向的空间</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * */</span></span><br><span class="line">    <span class="type">int</span> tmp;</span><br><span class="line">    tmp = *a;</span><br><span class="line">    *a = *b;</span><br><span class="line">    *b = tmp;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">(<span class="type">int</span> argc,<span class="type">char</span> *argv[])</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">     * argc：计数器，统计从终端传过来多少个参数</span></span><br><span class="line"><span class="comment">     * argv：是一个列表，保存命令中传递过来的参数，以字符指针数组形式储存</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * 查看</span></span><br><span class="line"><span class="comment">     * printf(&quot;argc=%d\n&quot;,argc);</span></span><br><span class="line"><span class="comment">     * for(int ar=0;ar&lt;argc;ar++)</span></span><br><span class="line"><span class="comment">     *      puts(argv[ar]);</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     **/</span></span><br><span class="line"></span><br><span class="line">    <span class="type">int</span> i = <span class="number">3</span>,j = <span class="number">5</span>;</span><br><span class="line">    print_value(&amp;i,&amp;j);</span><br><span class="line"></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;i=%d,b=%d\n&quot;</span>,i,j);</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>通过全局变量传参</li>
</ul>
<h4 id="函数的调用"><a href="#函数的调用" class="headerlink" title="函数的调用"></a>函数的调用</h4><ul>
<li><p>嵌套调用</p>
</li>
<li><p>递归调用</p>
<ul>
<li>嵌套调用的特例</li>
<li>一个函数直接或间接调用自身</li>
</ul>
</li>
<li><p>注意事项</p>
<ul>
<li>被调用函数需要写在当前函数(主调函数)的上方，或者在上方声明，才能正常调用<ul>
<li>函数申明:void 函数名(void);</li>
</ul>
</li>
</ul>
</li>
</ul>
<h4 id="函数与数组"><a href="#函数与数组" class="headerlink" title="函数与数组"></a>函数与数组</h4><ul>
<li><p>函数与一维数组</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">print_arr</span><span class="params">(<span class="type">int</span> *p,<span class="type">int</span> n)</span>&#123; <span class="comment">//int *p 可以写成 int p[],在形参中[]相当于*，与定义一个数组是含义是不一样的</span></span><br><span class="line">    <span class="comment">// sizeof(p) 指针变量p储存的是数组a的起始位置地址</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i&lt;n;i++)</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,*(p+i))</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&#x27;\n&#x27;</span>)</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">int</span> a[] = &#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>&#125;</span><br><span class="line"></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&#x27;%s:%d\n&#x27;</span>,__FUNCTION__,<span class="keyword">sizeof</span>(a)); <span class="comment">//main:20</span></span><br><span class="line"></span><br><span class="line">    print_arr(a,<span class="keyword">sizeof</span>(a)/<span class="keyword">sizeof</span>(*a)) <span class="comment">//需要传入数组长度，应为函数内部接收到的a只是数组起始地址</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>函数与二维数组</p>
</li>
<li><p>函数与字符数组</p>
</li>
</ul>
<h4 id="函数与指针"><a href="#函数与指针" class="headerlink" title="函数与指针"></a>函数与指针</h4><ul>
<li>指针函数<ul>
<li>返回值为为地址，用指针接收的函数,<strong>与整型函数，空函数</strong>意思一样</li>
<li>定义:<ul>
<li>返回值类型 * 函数名(形参)</li>
<li>int * fun(int a){ return 0xXXXXX }</li>
</ul>
</li>
</ul>
</li>
<li>函数指针<ul>
<li>指针指向的是函数，<strong>整型指针，指针指向整型数，数组指针，指针指向一个数组</strong>意思一样</li>
<li>定义<ul>
<li><code>类型 (*指针名) (形参)</code></li>
<li><code>int (*p)(int,int);</code> p &#x3D; add 指向相同类型的函数；add 是 int add(int a,int b){}</li>
</ul>
</li>
</ul>
</li>
<li>函数指针数组<ul>
<li>数组里存放的不是整型int，而是函数指针</li>
<li>定义<ul>
<li>类型 (*数组名[下标])(形参)</li>
<li>int (*arr[N])(int); 数组有N个元素，每个元素都是指向函数的指针</li>
</ul>
</li>
</ul>
</li>
<li>指向指针函数的函数指针数组<ul>
<li>函数指针数组的每个函数都是返回一个地址，都要通过指针来接收返回值</li>
</ul>
</li>
</ul>
<h3 id="构造类型"><a href="#构造类型" class="headerlink" title="构造类型"></a>构造类型</h3><ul>
<li><p>结构体</p>
<ul>
<li><p>结构体的产生以及意义</p>
<ul>
<li>为一系列不数据类型，提供连续内存空间类型</li>
<li>结构体是一个类似int的东西，不占用空间，不能拿来赋值给谁，只是描述指定结构体可以是怎样的数据</li>
</ul>
</li>
<li><p>类型描述</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> 结构体名&#123;</span></span><br><span class="line">    数据类型<span class="number">1</span> 成员<span class="number">1</span>；</span><br><span class="line">    数据类型<span class="number">2</span> 成员<span class="number">2</span>；</span><br><span class="line">    数据类型<span class="number">3</span> 成员<span class="number">3</span>；</span><br><span class="line">    <span class="type">int</span> age;</span><br><span class="line">    <span class="type">char</span> name[<span class="number">32</span>];</span><br><span class="line">    <span class="class"><span class="keyword">struct</span> 已存在的机构体名 对应变量;</span> </span><br><span class="line">    <span class="class"><span class="keyword">struct</span> &#123;</span>&#125; 对应变量;直接嵌套结构体 </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//无名结构图，直接定义变量</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span> &#123;</span></span><br><span class="line">    <span class="type">int</span> age,</span><br><span class="line">    <span class="type">char</span> name</span><br><span class="line">&#125;a,b=&#123;<span class="number">20</span>,liao&#125;,*p,...</span><br></pre></td></tr></table></figure>
<ul>
<li>建议定义在main函数外</li>
</ul>
</li>
<li><p>嵌套定义</p>
</li>
<li><p>定义变量，初始化以及成员引用</p>
<ul>
<li>结构体定义变量</li>
<li>struct 结构体名 变量 &#x3D; {1，2，3}</li>
<li>变量.age&#x3D;10;</li>
<li>成员引用<ul>
<li>变量.age</li>
<li>指针-&gt;成员名</li>
</ul>
</li>
</ul>
</li>
<li><p>占用内存空间大小</p>
<ul>
<li>默认，地址对齐情况<ul>
<li>某一个数据类型在该结构体字节位置%该数据类型所占的字节数 &#x3D;&#x3D; 0；不整除就向下移动，移动的字节空间，无法再使用</li>
<li>比如求结构体 struct case {int a;char b;float c;char d} 所占字节数<ul>
<li><p>结束分配addr第0、1、2、3、4、5、6、7、8、9、10、11、12、13个字节位置,加上该环境int是四个字节</p>
</li>
<li><p>0%sizeof(int) &#x3D;&#x3D; 0,int a 占用0、1、2、3;下一个从4开始</p>
</li>
<li><p>4%sizeof(char) &#x3D;&#x3D; 0,char b 占用4；</p>
</li>
<li><p>5%sizeof(float) !&#x3D; 0,下移</p>
</li>
<li><p>6%sizeof(float) !&#x3D; 0,下移</p>
</li>
<li><p>7%sizeof(float) !&#x3D; 0,下移;空闲3个，字节地址对齐</p>
</li>
<li><p>8%sizeof(float) &#x3D;&#x3D; 0,float c 占用8、9、10、11</p>
</li>
<li><p>12%sizeof(char) &#x3D;&#x3D; 0,char d 占用12，由于字节对齐，此处也会计算成4个字节 ，所以该结构体占用0-15共16个字节</p>
</li>
<li><p>公式:addr%类型所占字节数，整除则存放，否则向下偏移</p>
</li>
<li><p>如果int 8个字节，那么</p>
<ul>
<li>该结构体第一步就是0%8，最终结果会是32个字节</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>结构体禁用地址对齐<ul>
<li>struct case {xxxxx}<strong>attribute</strong>((packed))</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>小案例</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;stdlib.h&gt;</span></span></span><br><span class="line"><span class="meta">#default NAMESIZE 32</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">student_st</span>&#123;</span></span><br><span class="line">    <span class="type">int</span> id;</span><br><span class="line">    <span class="type">char</span> name[NAMESIZE]; <span class="comment">//name字符数组，变量.name直接是地址</span></span><br><span class="line">    <span class="type">int</span> math;</span><br><span class="line">    <span class="type">int</span> chinese;</span><br><span class="line">&#125;</span><br><span class="line"><span class="type">void</span> <span class="title function_">stu_set</span><span class="params">(<span class="keyword">struct</span> student_st *p)</span>&#123;</span><br><span class="line">    p-&gt;id = <span class="number">1</span>;</span><br><span class="line">    <span class="built_in">strncpy</span>(p-&gt;name,<span class="string">&quot;liao&quot;</span>,NAMESIZE);</span><br><span class="line">    p-&gt;math = <span class="number">90</span>;</span><br><span class="line">    p-&gt;chinese = <span class="number">100</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">stu_show</span><span class="params">(<span class="keyword">struct</span> student_st *p)</span>&#123;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;%d,%s,%d,%d\n&quot;</span>,p-&gt;id,p-&gt;name,p-&gt;math,p-&gt;chinese);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">stu_changename</span><span class="params">()</span>&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"><span class="type">int</span> main &#123;</span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">student_st</span> <span class="title">stu</span>;</span></span><br><span class="line">    stu_set(&amp;stu);</span><br><span class="line">    stu_show(&amp;stu);</span><br><span class="line">    stu_changename(&amp;stu);</span><br><span class="line">    <span class="built_in">exit</span>(<span class="number">0</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>共用体</p>
<ul>
<li>产生以及意义<ul>
<li>多个成员,只能一个成员生效,相当于多个选项，但只能选择一个</li>
<li>所占内存大小为最大的成员字节大小</li>
</ul>
</li>
<li>类型描述<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">union</span> 共用体名&#123;</span></span><br><span class="line">    数据类型 成员<span class="number">1</span>；</span><br><span class="line">    数据类型 成员<span class="number">2</span>；</span><br><span class="line">    数据类型 成员n；</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> main&#123;</span><br><span class="line">    <span class="class"><span class="keyword">union</span> 共用体名 变量;</span></span><br><span class="line">    <span class="class"><span class="keyword">union</span> 共用体名 指针;</span></span><br><span class="line">    变量.成员<span class="number">1</span> = xxxx;</span><br><span class="line">    指针名-&gt;成员<span class="number">1</span> = xxx;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li>嵌套定义使用</li>
<li>定义不同类型变量，初始化以及引用<ul>
<li>变量.成员</li>
<li>指针-&gt;成员</li>
</ul>
</li>
<li>内存占用空间大小</li>
<li>函数传参的问题(值，地址)</li>
<li>位域<ul>
<li>需再学一遍</li>
</ul>
</li>
</ul>
</li>
<li><p>枚举</p>
<ul>
<li>定义<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">enum</span> 枚举名称&#123;</span></span><br><span class="line">    成员<span class="number">1</span>, </span><br><span class="line">    成员<span class="number">2</span>,</span><br><span class="line">    成员<span class="number">3</span>,</span><br><span class="line">    ....</span><br><span class="line">&#125;</span><br><span class="line"><span class="type">int</span> main&#123;</span><br><span class="line">    <span class="class"><span class="keyword">enum</span> 枚举名称 变量 =</span> 成员<span class="number">1</span>；</span><br><span class="line">    直接 成员<span class="number">1</span> 当做全局变量使用</span><br><span class="line">    <span class="comment">// enum 成员为未赋值默认从0开始，变量最终为0；</span></span><br><span class="line">    <span class="comment">// 如果定义时成员1 = 10；后面的依次增加</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h3 id="动态内存管理"><a href="#动态内存管理" class="headerlink" title="动态内存管理"></a>动态内存管理</h3><blockquote>
<p>手动管理内存空间<br>相关函数malloc、ralloc、realloc、free (释放)<br>一般程序运行结束会自动释放,但是类似linux服务器一般不关机的，会不断需要内存，某些条件下必须手动控制<br>原则:谁申请谁释放 </p>
</blockquote>
<h4 id="malloc"><a href="#malloc" class="headerlink" title="malloc"></a>malloc</h4><blockquote>
<p>传入一个需要的内存大小，返回指定字节大小连续的内存起始地址 void *</p>
</blockquote>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> main&#123;</span><br><span class="line">    <span class="type">int</span> *p = <span class="literal">NULL</span>;</span><br><span class="line">    p = <span class="built_in">malloc</span>(<span class="keyword">sizeof</span>(<span class="type">int</span>)) <span class="comment">//需要int大小的字节数</span></span><br><span class="line">    <span class="keyword">if</span>(p==<span class="literal">NULL</span>)&#123; <span class="comment">//如果malloc失败</span></span><br><span class="line">        <span class="built_in">exit</span>(<span class="number">1</span>)</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//一些列操作</span></span><br><span class="line">    *p =<span class="number">10</span></span><br><span class="line">        </span><br><span class="line">    <span class="built_in">free</span>(p) <span class="comment">//释放</span></span><br><span class="line">    <span class="built_in">exit</span>(<span class="number">0</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h4 id="calloc"><a href="#calloc" class="headerlink" title="calloc"></a>calloc</h4><blockquote>
<p>参数1指定几个成员，参数2每个成员需要的大小<br>申请n个成员指定大小的，连续内存空间返回void *</p>
</blockquote>
<h4 id="realloc"><a href="#realloc" class="headerlink" title="realloc"></a>realloc</h4><blockquote>
<p>重新分配一个动态内存空间<br>参数1为malloc或calloc返回的指针，参数2重新分配的大小，在原来基础上将大小扩展到重新分配的大小</p>
</blockquote>
<h4 id="free"><a href="#free" class="headerlink" title="free"></a>free</h4><blockquote>
<p>释放之前调用 calloc、malloc 或 realloc 所分配的内存空间。<br>指针free后，最好将它赋为NULL<br>free后原来指向的地址还存在，对那块空间没有了引用的权限，若需要使用该指针可以给它重新分配内存<br>free 释放的是指针指向的内存,指针是一个变量，只有程序结束时才被销毁,释放了内存空间后，原来指向这块空间的指针还存在，只不过现在指针指向的内容是无用的,未定义的<br>(重新学习P63与free后一半)</p>
</blockquote>
<h3 id="调试工具和调试技巧-gdb、make"><a href="#调试工具和调试技巧-gdb、make" class="headerlink" title="调试工具和调试技巧(gdb、make)"></a>调试工具和调试技巧(gdb、make)</h3><h3 id="常用内置方法"><a href="#常用内置方法" class="headerlink" title="常用内置方法"></a>常用内置方法</h3><ul>
<li><code>typeof(x)</code>:获取 x 的类型</li>
</ul>
<h3 id="关键字"><a href="#关键字" class="headerlink" title="关键字"></a>关键字</h3><ul>
<li><code>typedef</code>:为已有的数据类型改名<ul>
<li>typedef 已有数据类型 新类型名;(必须分号)</li>
<li>typedef int INT;</li>
<li>typedef int ARR[6] —&gt; ARR array  —&gt; int array[6] </li>
<li>typedef int FUNC(int) —&gt; 给int(int)int类型int参数的函数改名FUNC  —&gt; FUNC f 相当于 int f(int) <figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span>&#123;</span></span><br><span class="line">    <span class="type">int</span> i;</span><br><span class="line">    <span class="type">float</span> f;</span><br><span class="line">&#125;NODE,*NODET;</span><br><span class="line"><span class="comment">//定义一个 结构体 别名叫 NODE,定义一个 结构体* 叫 NODET</span></span><br></pre></td></tr></table></figure></li>
<li>如果不同环境需要将int改成long，那么用typedef long INT；</li>
</ul>
</li>
</ul>
<h3 id="常用库函数"><a href="#常用库函数" class="headerlink" title="常用库函数"></a>常用库函数</h3><ul>
<li>man 函数名：就可以指定调用这个函数需要引入什么头文件</li>
</ul>
<h3 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h3><ul>
<li>连个函数名相同，参数不想听的函数，如何判断是用重载实现还是变参实现?<ul>
<li>调用是多传参数，编译报语法错误，那就是重载定参的</li>
<li>如果编译不报错，使用才报错说明是变参实现的，函数本身都不知道需要多少参数</li>
</ul>
</li>
</ul>
<h3 id="系统宏"><a href="#系统宏" class="headerlink" title="系统宏"></a>系统宏</h3><ul>
<li><strong>FUNCTION</strong>:函数名</li>
<li><strong>LINE</strong>:当前行号</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://example.com">lzoxun</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/2023/07/22/server/C/C-base/">http://example.com/2023/07/22/server/C/C-base/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">学习笔记</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/07/22/server/Ruby/ruby-sass/" title="sass"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">sass</div></div></a></div><div class="next-post pull-right"><a href="/2023/07/22/server/Ruby/ruby-setting/" title="ruby工具"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">ruby工具</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">lzoxun</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">108</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/liaozhongxun"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/liaozhongxun" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:869664233@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">这是我的文档</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A6%82%E5%BF%B5"><span class="toc-number">1.</span> <span class="toc-text">概念</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AF%AD%E6%B3%95"><span class="toc-number">2.</span> <span class="toc-text">语法</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E8%A6%81%E6%B1%82"><span class="toc-number">2.1.</span> <span class="toc-text">基本要求</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E3%80%81%E8%BF%90%E7%AE%97%E7%AC%A6%E3%80%81%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="toc-number">2.2.</span> <span class="toc-text">数据类型、运算符、表达式</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.2.1.</span> <span class="toc-text">数据类型</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%E4%B8%8E%E5%B8%B8%E9%87%8F"><span class="toc-number">2.2.2.</span> <span class="toc-text">变量与常量</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">2.2.3.</span> <span class="toc-text">运算符</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="toc-number">2.2.4.</span> <span class="toc-text">表达式</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA%E4%B8%93%E9%A2%98"><span class="toc-number">2.3.</span> <span class="toc-text">输入输出专题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9B%E5%88%B6"><span class="toc-number">2.4.</span> <span class="toc-text">进制</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%81%E7%A8%8B%E6%8E%A7%E5%88%B6"><span class="toc-number">2.5.</span> <span class="toc-text">流程控制</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%A1%BA%E5%BA%8F"><span class="toc-number">2.5.1.</span> <span class="toc-text">顺序</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%80%89%E6%8B%A9"><span class="toc-number">2.5.2.</span> <span class="toc-text">选择</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%BE%AA%E7%8E%AF"><span class="toc-number">2.5.3.</span> <span class="toc-text">循环</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%BE%85%E5%8A%A9%E6%8E%A7%E5%88%B6%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">2.5.4.</span> <span class="toc-text">辅助控制关键字</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E7%BB%84"><span class="toc-number">2.6.</span> <span class="toc-text">数组</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84"><span class="toc-number">2.6.1.</span> <span class="toc-text">二维数组</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84-1"><span class="toc-number">2.6.2.</span> <span class="toc-text">二维数组</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E6%95%B0%E7%BB%84"><span class="toc-number">2.6.3.</span> <span class="toc-text">字符数组</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E5%87%BD%E6%95%B0"><span class="toc-number">2.6.4.</span> <span class="toc-text">字符串常用函数</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8C%87%E9%92%88"><span class="toc-number">2.7.</span> <span class="toc-text">指针</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%E4%B8%8E%E5%9C%B0%E5%9D%80"><span class="toc-number">2.7.1.</span> <span class="toc-text">变量与地址</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8C%87%E9%92%88%E4%B8%8E%E6%8C%87%E9%92%88%E5%8F%98%E9%87%8F"><span class="toc-number">2.7.2.</span> <span class="toc-text">指针与指针变量</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%9B%B4%E6%8E%A5%E8%AE%BF%E9%97%AE%E4%B8%8E%E9%97%B4%E6%8E%A5%E8%AE%BF%E9%97%AE"><span class="toc-number">2.7.3.</span> <span class="toc-text">直接访问与间接访问</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%A9%BA%E6%8C%87%E9%92%88%E4%B8%8E%E9%87%8E%E6%8C%87%E9%92%88"><span class="toc-number">2.7.4.</span> <span class="toc-text">空指针与野指针</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%A9%BA%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.7.5.</span> <span class="toc-text">空类型</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%9A%E4%B9%89%E4%B8%8E%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9A%84%E4%B9%A6%E5%86%99%E8%A7%84%E5%88%99"><span class="toc-number">2.7.6.</span> <span class="toc-text">定义与初始化的书写规则</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8C%87%E9%92%88%E8%BF%90%E7%AE%97"><span class="toc-number">2.7.7.</span> <span class="toc-text">指针运算</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8C%87%E9%92%88%E4%B8%8E%E6%95%B0%E7%BB%84"><span class="toc-number">2.7.8.</span> <span class="toc-text">指针与数组</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#const-%E4%B8%8E%E6%8C%87%E9%92%88"><span class="toc-number">2.7.9.</span> <span class="toc-text">const 与指针</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8C%87%E9%92%88%E6%95%B0%E7%BB%84%E4%B8%8E%E6%95%B0%E7%BB%84%E6%8C%87%E9%92%88"><span class="toc-number">2.7.10.</span> <span class="toc-text">指针数组与数组指针</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%A4%9A%E7%BA%A7%E6%8C%87%E9%92%88"><span class="toc-number">2.7.11.</span> <span class="toc-text">多级指针</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%87%BD%E6%95%B0"><span class="toc-number">2.8.</span> <span class="toc-text">函数</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%87%BD%E6%95%B0%E7%9A%84%E5%AE%9A%E4%B9%89"><span class="toc-number">2.8.1.</span> <span class="toc-text">函数的定义</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%87%BD%E6%95%B0%E7%9A%84%E4%BC%A0%E5%8F%82"><span class="toc-number">2.8.2.</span> <span class="toc-text">函数的传参</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%87%BD%E6%95%B0%E7%9A%84%E8%B0%83%E7%94%A8"><span class="toc-number">2.8.3.</span> <span class="toc-text">函数的调用</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%87%BD%E6%95%B0%E4%B8%8E%E6%95%B0%E7%BB%84"><span class="toc-number">2.8.4.</span> <span class="toc-text">函数与数组</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%87%BD%E6%95%B0%E4%B8%8E%E6%8C%87%E9%92%88"><span class="toc-number">2.8.5.</span> <span class="toc-text">函数与指针</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9E%84%E9%80%A0%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.9.</span> <span class="toc-text">构造类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8A%A8%E6%80%81%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86"><span class="toc-number">2.10.</span> <span class="toc-text">动态内存管理</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#malloc"><span class="toc-number">2.10.1.</span> <span class="toc-text">malloc</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#calloc"><span class="toc-number">2.10.2.</span> <span class="toc-text">calloc</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#realloc"><span class="toc-number">2.10.3.</span> <span class="toc-text">realloc</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#free"><span class="toc-number">2.10.4.</span> <span class="toc-text">free</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%B0%83%E8%AF%95%E5%B7%A5%E5%85%B7%E5%92%8C%E8%B0%83%E8%AF%95%E6%8A%80%E5%B7%A7-gdb%E3%80%81make"><span class="toc-number">2.11.</span> <span class="toc-text">调试工具和调试技巧(gdb、make)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E5%86%85%E7%BD%AE%E6%96%B9%E6%B3%95"><span class="toc-number">2.12.</span> <span class="toc-text">常用内置方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">2.13.</span> <span class="toc-text">关键字</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E5%BA%93%E5%87%BD%E6%95%B0"><span class="toc-number">2.14.</span> <span class="toc-text">常用库函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%97%AE%E9%A2%98"><span class="toc-number">2.15.</span> <span class="toc-text">问题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%B3%BB%E7%BB%9F%E5%AE%8F"><span class="toc-number">2.16.</span> <span class="toc-text">系统宏</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-11/" title="win 11 set">win 11 set</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-gitbash/" title="git bash">git bash</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-wsl/" title="wsl">wsl</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-main/" title="window">window</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/web/%E5%85%BC%E5%AE%B9%E9%97%AE%E9%A2%98/" title="兼容问题">兼容问题</a><time datetime="2023-07-22T07:14:09.699Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By lzoxun</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><div class="js-pjax"></div><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-nest.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div class="no-result" id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"jsonPath":"/live2dw/assets/haruto.model.json"},"display":{"position":"right","width":100,"height":200,"right":300},"mobile":{"show":true}});</script></body></html>